[tooltip] {
  position: relative;

  & > * {
    display: inline-block;
  }

  &:before,
  &:after {
    text-transform: none;
    font-size: 13px;
    line-height: 1;
    user-select: none;
    pointer-events: none;
    position: absolute;
    display: none;
    opacity: 0;
  }
  &:before {
    content: '';
    border: 5px solid transparent;
    z-index: 1001;
  }
  &:after {
    content: attr(tooltip);

    text-align: center;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 7px;
    border-radius: 5px;
    box-shadow: var(--shadow);
    background: var(--kungalgame-trans-white-2);
    backdrop-filter: blur(10px);
    will-change: transform;
    color: var(--kungalgame-blue-5);
    z-index: 1000;
  }

  &:hover:before,
  &:hover:after {
    display: block;
  }

  &:not([position]):before,
  &[position^='top']:before {
    bottom: 100%;
    border-bottom-width: 0;
    border-top-color: var(--kungalgame-trans-white-2);
  }
  &:not([position]):after,
  &[position^='top']::after {
    bottom: calc(100% + 5px);
  }

  &:not([position])::before,
  &:not([position])::after,
  &[position^='top']::before,
  &[position^='top']::after {
    left: 50%;
    transform: translate(-50%, -10px);
  }

  &[position^='bottom']::before {
    top: 105%;
    border-top-width: 0;
    border-bottom-color: var(--kungalgame-trans-white-2);
  }
  &[position^='bottom']::after {
    top: calc(105% + 5px);
  }
  &[position^='bottom']::before,
  &[position^='bottom']::after {
    left: 50%;
    transform: translate(-50%, 10px);
  }

  &[position^='left']::before {
    top: 50%;
    border-right-width: 0;
    border-left-color: var(--kungalgame-trans-white-2);
    left: calc(0em - 5px);
    transform: translate(-10px, -50%);
  }
  &[position^='left']::after {
    top: 50%;
    right: calc(100% + 5px);
    transform: translate(-10px, -50%);
  }

  &[position^='right']::before {
    top: 50%;
    border-left-width: 0;
    border-right-color: var(--kungalgame-trans-white-2);
    right: calc(0em - 5px);
    transform: translate(10px, -50%);
  }
  &[position^='right']::after {
    top: 50%;
    left: calc(100% + 5px);
    transform: translate(10px, -50%);
  }

  &:not([position]):hover::before,
  &:not([position]):hover::after,
  &[position^='top']:hover::before,
  &[position^='top']:hover::after,
  &[position^='bottom']:hover::before,
  &[position^='bottom']:hover::after {
    animation: vertical 300ms ease-out forwards;
  }

  &[position^='left']:hover::before,
  &[position^='left']:hover::after,
  &[position^='right']:hover::before,
  &[position^='right']:hover::after {
    animation: horizontal 300ms ease-out forwards;
  }
}

/* Empty tooltips */
[tooltip='']::before,
[tooltip='']::after {
  display: none !important;
}

@keyframes vertical {
  to {
    opacity: 0.9;
    transform: translate(-50%, 0);
  }
}

@keyframes horizontal {
  to {
    opacity: 0.9;
    transform: translate(0, -50%);
  }
}
